home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / mui38dev-storm / examples / popup.c < prev    next >
C/C++ Source or Header  |  1999-09-13  |  5KB  |  205 lines

  1. #include "demo.h"
  2.  
  3.  
  4. SAVEDS ASM LONG StrObjFunc(REG(a2) Object *pop,REG(a1) Object *str)
  5. {
  6.     char *x,*s;
  7.     int i;
  8.  
  9.     get(str,MUIA_String_Contents,&s);
  10.  
  11.     for (i=0;;i++)
  12.     {
  13.         DoMethod(pop,MUIM_List_GetEntry,i,&x);
  14.         if (!x)
  15.         {
  16.             set(pop,MUIA_List_Active,MUIV_List_Active_Off);
  17.             break;
  18.         }
  19.         else if (!stricmp(x,s))
  20.         {
  21.             set(pop,MUIA_List_Active,i);
  22.             break;
  23.         }
  24.     }
  25.     return(TRUE);
  26. }
  27.  
  28. /*FR* Added StormC compability */
  29. #ifdef __STORM__
  30. VOID SAVEDS ASM ObjStrFunc(REG(a2) Object *pop,REG(a1) Object *str)
  31. #else
  32. SAVEDS ASM VOID ObjStrFunc(REG(a2) Object *pop,REG(a1) Object *str)
  33. #endif
  34. {
  35.     char *x;
  36.     DoMethod(pop,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&x);
  37.     set(str,MUIA_String_Contents,x);
  38. }
  39.  
  40.  
  41. #ifdef __STORM__
  42. VOID SAVEDS ASM WindowFunc(REG(a2) Object *pop,REG(a1) Object *win)
  43. #else
  44. SAVEDS ASM VOID WindowFunc(REG(a2) Object *pop,REG(a1) Object *win)
  45. #endif
  46. {
  47.     set(win,MUIA_Window_DefaultObject,pop);
  48. }
  49.  
  50.  
  51. static const char *PopNames[] =
  52. {
  53.     "Stefan Becker",
  54.     "Dirk Federlein",
  55.     "Georg Heßmann",
  56.     "Martin Horneffer",
  57.     "Martin Huttenloher",
  58.     "Kai Iske",
  59.     "Oliver Kilian",
  60.     "Franke Mariak",
  61.     "Klaus Melchior",
  62.     "Armin Sander",
  63.     "Matthias Scheler",
  64.     "Andreas Schildbach",
  65.     "Wolfgang Schildbach",
  66.     "Christian Scholz",
  67.     "Stefan Sommerfeld",
  68.     "Markus Stipp",
  69.     "Henri Veistera",
  70.     "Albert Weinert",
  71.     "Michael-W. Hohmann",
  72.     "Stefan Burstroem",
  73.     NULL
  74. };
  75.  
  76.  
  77. int main(int argc,char *argv[])
  78. {
  79.     static const struct Hook StrObjHook = { { NULL,NULL },(VOID *)StrObjFunc,NULL,NULL };
  80.     static const struct Hook ObjStrHook = { { NULL,NULL },(VOID *)ObjStrFunc,NULL,NULL };
  81.     static const struct Hook WindowHook = { { NULL,NULL },(VOID *)WindowFunc,NULL,NULL };
  82.     APTR app,window,pop1,pop2,pop3,pop4,pop5,plist;
  83.     ULONG signals;
  84.     BOOL running = TRUE;
  85.  
  86.     init();
  87.  
  88.     app = ApplicationObject,
  89.         MUIA_Application_Title      , "Popup-Demo",
  90.         MUIA_Application_Version    , "$VER: Popup-Demo 19.5 (12.02.97)",
  91.         MUIA_Application_Copyright  , "©1993, Stefan Stuntz",
  92.         MUIA_Application_Author     , "Stefan Stuntz",
  93.         MUIA_Application_Description, "Demostrate popup objects.",
  94.         MUIA_Application_Base       , "POPUP",
  95.  
  96.         SubWindow, window = WindowObject,
  97.             MUIA_Window_Title, "Popup Objects",
  98.             MUIA_Window_ID   , MAKE_ID('P','O','P','P'),
  99.             WindowContents, VGroup,
  100.  
  101.                 Child, ColGroup(2),
  102.  
  103.                     Child, KeyLabel2("File:",'f'),
  104.                     Child, pop1 = PopaslObject,
  105.                         MUIA_Popstring_String, KeyString(0,256,'f'),
  106.                         MUIA_Popstring_Button, PopButton(MUII_PopFile),
  107.                         ASLFR_TitleText, "Please select a file...",
  108.                         End,
  109.  
  110.                     Child, KeyLabel2("Drawer:",'d'),
  111.                     Child, pop2 = PopaslObject,
  112.                         MUIA_Popstring_String, KeyString(0,256,'d'),
  113.                         MUIA_Popstring_Button, PopButton(MUII_PopDrawer),
  114.                         ASLFR_TitleText  , "Please select a drawer...",
  115.                         ASLFR_DrawersOnly, TRUE,
  116.                         End,
  117.  
  118.                     Child, KeyLabel2("Font:",'o'),
  119.                     Child, pop3 = PopaslObject,
  120.                         MUIA_Popstring_String, KeyString(0,80,'o'),
  121.                         MUIA_Popstring_Button, PopButton(MUII_PopUp),
  122.                         MUIA_Popasl_Type , ASL_FontRequest,
  123.                         ASLFO_TitleText  , "Please select a font...",
  124.                         End,
  125.  
  126.                     Child, KeyLabel2("Fixed Font:",'i'),
  127.                     Child, pop4 = PopaslObject,
  128.                         MUIA_Popstring_String, KeyString(0,80,'i'),
  129.                         MUIA_Popstring_Button, PopButton(MUII_PopUp),
  130.                         MUIA_Popasl_Type , ASL_FontRequest,
  131.                         ASLFO_TitleText  , "Please select a fixed font...",
  132.                         ASLFO_FixedWidthOnly, TRUE,
  133.                         End,
  134.  
  135.                     Child, KeyLabel2("Thanks To:",'n'),
  136.                     Child, pop5 = PopobjectObject,
  137.                         MUIA_Popstring_String, KeyString(0,60,'n'),
  138.                         MUIA_Popstring_Button, PopButton(MUII_PopUp),
  139.                         MUIA_Popobject_StrObjHook, &StrObjHook,
  140.                         MUIA_Popobject_ObjStrHook, &ObjStrHook,
  141.                         MUIA_Popobject_WindowHook, &WindowHook,
  142.                         MUIA_Popobject_Object, plist = ListviewObject,
  143.                             MUIA_Listview_List, ListObject,
  144.                                 InputListFrame,
  145.                                 MUIA_List_SourceArray, PopNames,
  146.                                 End,
  147.                             End,
  148.                         End,
  149.                     End,
  150.                 End,
  151.             End,
  152.         End;
  153.  
  154.     if (!app)
  155.         fail(app,"Failed to create Application.");
  156.  
  157.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  158.         app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  159.  
  160.     DoMethod(window,MUIM_Window_SetCycleChain,pop1,pop2,pop3,pop4,pop5,NULL);
  161.  
  162.     /* A double click terminates the popping list with a successful return value. */
  163.     DoMethod(plist,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  164.         pop5,2,MUIM_Popstring_Close,TRUE);
  165.  
  166.  
  167. /*
  168. ** Input loop...
  169. */
  170.  
  171.     set(window,MUIA_Window_Open,TRUE);
  172.  
  173.     while (running)
  174.     {
  175.         switch (DoMethod(app,MUIM_Application_Input,&signals))
  176.         {
  177.             case MUIV_Application_ReturnID_Quit:
  178.             {
  179.              LONG active;
  180.  
  181.                 get(pop1,MUIA_Popasl_Active,&active);
  182.                 if (!active) get(pop2,MUIA_Popasl_Active,&active);
  183.                 if (!active) get(pop3,MUIA_Popasl_Active,&active);
  184.                 if (!active) get(pop4,MUIA_Popasl_Active,&active);
  185.  
  186.                 if (active)
  187.                     MUI_Request(app,window,0,NULL,"OK","Cannot quit now, still\nsome asl popups opened.");
  188.                 else
  189.                     running = FALSE;
  190.             }
  191.             break;
  192.         }
  193.  
  194.         if (running && signals) Wait(signals);
  195.     }
  196.  
  197.     set(window,MUIA_Window_Open,FALSE);
  198.  
  199. /*
  200. ** Shut down...
  201. */
  202.  
  203.     fail(app,NULL);
  204. }
  205.